package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.sc.nft.dto.MallActivitySpecsGetSendCodeDTO;
import com.sc.nft.entity.MallActivity;
import com.sc.nft.entity.MallProductSpecs;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.MallActivitySpecs;
import com.sc.nft.mapper.MallActivitySpecsMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

/**
 * IP商城活动规格表(sc_mall_activity_specs)数据DAO
 *
 * @author zxy
 * @description IP商城
 * @since 2023-05-10 16:59:01
 */
@Slf4j
@Repository
public class MallActivitySpecsDao extends ServiceImpl<MallActivitySpecsMapper, MallActivitySpecs> {

    public List<MallActivitySpecs> getByActivityId(Long activityId) {
        LambdaQueryWrapper<MallActivitySpecs> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MallActivitySpecs::getActivityId, activityId);
        return list(wrapper);
    }

    public Boolean frozenStockByIdAndCount(Long id, Integer count) {
        return baseMapper.frozenStockByIdAndCount(id, count);
    }

    public Boolean subFrozenCount(Long id, Integer count) {
        return baseMapper.subFrozenCount(id, count);
    }

    public Boolean frozenConsumeStockByIdAndCount(Long id, Integer count) {
        return baseMapper.frozenConsumeStockByIdAndCount(id, count);
    }

    /**
     * 出入库存
     *
     * @param addCount 添加库存数量
     * @return
     */
    public Boolean updateUsableStockCountById(Long id, Integer addCount) {
        return baseMapper.updateUsableStockCountById(id, addCount);
    }

    /**
     * 修改活动销售价格
     *
     * @param id
     * @param salesPrice
     */
    public void updateMallActivitySalesPriceById(Long id, BigDecimal salesPrice, BigDecimal profit) {
        UpdateWrapper<MallActivitySpecs> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id", id);
        updateWrapper.set("sales_price", salesPrice);
        updateWrapper.set("profit", profit);
        baseMapper.update(new MallActivitySpecs(), updateWrapper);
    }

    public boolean updateProfitTemplateId(Long profitTemplateId) {
        UpdateWrapper<MallActivitySpecs> wrapper = new UpdateWrapper<>();
        wrapper.set("profit_template_id", profitTemplateId);
        return update(new MallActivitySpecs(), wrapper);
    }

    public MallActivitySpecs getByIdWithoutDeleted(Long activitySpecsId) {
        return baseMapper.getByIdWithoutDeleted(activitySpecsId);
    }

    public List<MallActivitySpecsGetSendCodeDTO> getSendCodeByActivitySpecsIdList(List<Long> activitySpecsIdList) {
        return baseMapper.getSendCodeByActivitySpecsIdList(activitySpecsIdList);
    }
}